using System.CodeDom;
using CodeDomHelper.Types;
using System;
using System.Diagnostics;

namespace CodeDomHelper.CodeDom
{
    [DebuggerDisplay("{PropertyName}", Name = "PropertyExp")]
    [Serializable()]
    [System.Diagnostics.DebuggerStepThrough()]
    public partial class PropertyExp : CodePropertyReferenceExpression, IType
    {

        #region Ctor

        public PropertyExp(System.CodeDom.CodeExpression targetObject, string propertyName, string typeName)
            : base(targetObject, propertyName)
        {
            Type = new TypeExp(typeName);
        }

        public PropertyExp(System.CodeDom.CodeExpression targetObject, string propertyName, Type type)
            : base(targetObject, propertyName)
        {
            Type = new TypeExp(type);
        }

        public PropertyExp(System.CodeDom.CodeExpression targetObject, string propertyName, TypeExp type)
            : base(targetObject, propertyName)
        {
            Type = new TypeExp(type);
        }

        public PropertyExp(System.CodeDom.CodeExpression targetObject, string propertyName, TypeExpression type)
            : base(targetObject, propertyName)
        {
            Type = new TypeExp(type);
        }

        #endregion

        public TypeExp Type { get; private set; }

        #region Property

        public PropertyExp Property(string propertyName, string typeName)
        {
            return new PropertyExp(this, propertyName, typeName);
        }

        public PropertyExp Property(string propertyName, TypeExp type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        public PropertyExp Property(string propertyName, Type type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        public PropertyExp Property(string propertyName, TypeExpression type)
        {
            return new PropertyExp(this, propertyName, type);
        }

        #endregion

        #region Field

        public FieldExp Field(string fieldName, string typeName)
        {
            return new FieldExp(this, fieldName, typeName);
        }

        public FieldExp Field(string fieldName, TypeExp type)
        {
            return new FieldExp(this, fieldName, type);
        }

        public FieldExp Field(string fieldName, Type type)
        {
            return new FieldExp(this, fieldName, type);
        }

        public FieldExp Field(string fieldName, TypeExpression type)
        {
            return new FieldExp(this, fieldName, type);
        }

        #endregion

        #region Method

        public MethodExp Method(string methodName)
        {
            return new MethodExp(this, methodName);
        }

        public MethodExp Method(string methodName, TypeExp typeReturn)
        {
            return new MethodExp(this, methodName, typeReturn);
        }

        #endregion


        public CastExp As(TypeExp type)
        {
            return Helper.Cast(this, type);
        }

        public static implicit operator ParameterExp(PropertyExp property)
        {
            return new ParameterExp(property.Type, property.PropertyName);
        }
    }

}
